package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.wxvo.WxSearchClearHistoryVO;
import com.cskaoyan.bean.wxvo.WxSearchIndexVO;
import com.cskaoyan.service.WxKeywordService;
import com.cskaoyan.utils.wx.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/search")
public class WxSearchController {
    @Autowired
    WxKeywordService wxKeywordService;

    @RequestMapping("index")
    public BaseRespVo wxSearchIndex() {
        Integer userId = UserUtil.getUserId();
        WxSearchIndexVO wxSearchIndexVO = wxKeywordService.searchIndex(userId);
        return BaseRespVo.ok(wxSearchIndexVO);
    }

    @RequestMapping("helper")
//    返回值是一个包含keyword的数组
    public BaseRespVo wxSearchHelper(String keyword){
        String [] data=wxKeywordService.searchHelper(keyword);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("clearhistory")
    public WxSearchClearHistoryVO wxSearchClearHistory(){
        Integer userId = UserUtil.getUserId();
        wxKeywordService.SearchClearHistory(userId);
        return WxSearchClearHistoryVO.ok();
    }

}
